﻿// E-Book Copier
// Copyright (C) 2009 Chuan-Gen Fan
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Project: http://code.google.com/p/ebookcopier/
// Contact Author:
//    website: http://chuangen.name/
// e-mail/msn: chuangen@live.cn

using System;
using System.Collections.Generic;
using System.Text;

namespace EbookCopier
{
    /// <summary>
    /// Apabi Reader v3.2 翻页命令器。
    /// 启动程序后，循环判断Apabi是否运行中，如果未启动，则自动截图按钮为灰色；如果启动了则可用。
    /// </summary>
    /// <remarks>
    /// Apabi Reader v3.2 WM_COMMAND 消息参数：
    ///   首页: 0x00008033
    ///   尾页: 0x00008034
    /// 上一页: 0x00008008
    /// 下一页: 0x00008007
    /// 设置单页模式: 0x00008009
    /// </remarks>
    [Cmder("{59C9FBF2-8A07-4a66-8494-C84BEAA24B48}","Apabi Reader 3.2", HasEditableOptions=false)]
    public partial class Apabi32Cmder : WmCommandCmder
    {
        /// <summary>
        /// 初始化类 <see cref="Apabi32Cmder"/> 的新实例。
        /// </summary>
        public Apabi32Cmder()
            : base(0x00008033,0x00008034, 0x00008008, 0x00008007)
        {}

        string titleStartsWith = "Apabi Reader";
        /// <summary>
        /// 字符串是否匹配要查找的窗口标题。
        /// </summary>
        /// <param name="text">要判断的窗口标题</param>
        /// <returns>True=匹配; False=不匹配</returns>
        protected override bool MatchWindowText(string text)
        {
            return text.StartsWith(titleStartsWith);
        }
        /// <summary>
        /// 获取 Apabi Reader 当前打开的文档名称。
        /// </summary>
        /// <returns>文档标题</returns>
        public override string GetDocumentTitle()
        {
            string title = base.GetWindowText();

            string start = titleStartsWith + " - [";
            if (title.StartsWith(start) && title.EndsWith("]"))
                return title.Substring(start.Length, title.Length - start.Length - 1);
            else
                return null;
        }
    }
}
